// import com.alibaba.druid.sql.ast.SQLExpr*;
// import com.alibaba.druid.sql.ast.SQLName*;
// import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;

#include "../../../../../sql/dialect/mysql/ast/statement/MySqlExtPartition.h"
#include "../../../../../sql/dialect/mysql/visitor/MySqlASTVisitor.h"
#include "../../../../../sql/ast/SQLName.h"
#include "../../../../../sql/ast/SQLExpr.h"

// @Override
void MySqlExtPartition_Item::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlExtPartition_Item)))
  {
    acceptChild(visitor, dbPartition);
    acceptChild(visitor, dbPartitionBy);
    acceptChild(visitor, tbPartition);
    acceptChild(visitor, tbPartitionBy);
  }
  visitor->endVisit(SharedObject(MySqlExtPartition_Item));
}

SQLObject_ptr MySqlExtPartition_Item::clone()
{
  SQLObject_ptr clone_tmp = MySqlExtPartition_Item_ptr(new MySqlExtPartition_Item());
  MySqlExtPartition_Item_ptr x = std::dynamic_pointer_cast<MySqlExtPartition_Item>(clone_tmp);
  // MySqlExtPartition_Item_ptrx = new MySqlExtPartition_Item();

  if (dbPartition != nullptr)
  {
    x->setDbPartition(std::dynamic_pointer_cast<SQLName>(dbPartition->clone()));
  }

  if (dbPartitionBy != nullptr)
  {
    x->setDbPartitionBy(std::dynamic_pointer_cast<SQLExpr>(dbPartitionBy->clone()));
  }

  if (tbPartition != nullptr)
  {
    x->setTbPartition(std::dynamic_pointer_cast<SQLName>(tbPartition->clone()));
  }

  if (tbPartitionBy != nullptr)
  {
    x->setTbPartitionBy(std::dynamic_pointer_cast<SQLExpr>(tbPartitionBy->clone()));
  }

  return x;
}

SQLName_ptr MySqlExtPartition_Item::getDbPartition()
{
  return dbPartition;
}

void MySqlExtPartition_Item::setDbPartition(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(MySqlExtPartition_Item));
  }
  this->dbPartition = x;
}

SQLName_ptr MySqlExtPartition_Item::getTbPartition()
{
  return tbPartition;
}

void MySqlExtPartition_Item::setTbPartition(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(MySqlExtPartition_Item));
  }
  this->tbPartition = x;
}

SQLExpr_ptr MySqlExtPartition_Item::getDbPartitionBy()
{
  return dbPartitionBy;
}

void MySqlExtPartition_Item::setDbPartitionBy(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(MySqlExtPartition_Item));
  }
  this->dbPartitionBy = x;
}

SQLExpr_ptr MySqlExtPartition_Item::getTbPartitionBy()
{
  return tbPartitionBy;
}

void MySqlExtPartition_Item::setTbPartitionBy(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(MySqlExtPartition_Item));
  }
  this->tbPartitionBy = x;
}

MySqlExtPartition::MySqlExtPartition()
{
  items = std::make_shared<std::list<MySqlExtPartition_Item_ptr>>();
}

std::shared_ptr<std::list<MySqlExtPartition_Item_ptr>> MySqlExtPartition::getItems()
{
  return items;
}

// @Override
void MySqlExtPartition::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlExtPartition)))
  {
    auto it_items = items->begin();
    for (int i = 0; i < items->size(); i++)
    {
      std::advance(it_items, i);
      (*it_items)->accept(visitor);
    }
  }
  visitor->endVisit(SharedObject(MySqlExtPartition));
}

SQLObject_ptr MySqlExtPartition::clone()
{
  SQLObject_ptr clone_tmp = MySqlExtPartition_ptr(new MySqlExtPartition());
  MySqlExtPartition_ptr x = std::dynamic_pointer_cast<MySqlExtPartition>(clone_tmp);
  // MySqlExtPartition *x = new MySqlExtPartition();
  for (MySqlExtPartition_Item_ptr item : *items)
  {
    MySqlExtPartition_Item_ptr item1 = std::dynamic_pointer_cast<MySqlExtPartition_Item>(item->clone());
    item1->setParent(x);
    x->items->push_back(item1);
  }
  return x;
}
